/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Vista;


import Entidades.SolicitudTraslado;
import Servicios.Dao.Impl.OrganoDaoImpl;
import Servicios.Dao.Impl.SolicitudTrasladoDaoImpl;
import Servicios.Dao.OrganoDao;
import Servicios.Dao.SolicitudTrasladoDao;
import java.sql.Connection;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JOptionPane;


/**
 *
 * @author TRACY
 */
public class GestionarCotizacion2 extends javax.swing.JFrame {
    
    public Connection cn;
    SolicitudTrasladoDao solicitudTrasladoDao;
    String idSolicitud, idOrgano;
    SolicitudTraslado solicitudtraslado;
    OrganoDao organoDao;
    
    public GestionarCotizacion2(){
        initComponents();
    }
    
    public GestionarCotizacion2(String idSolicitud, Connection cn) {
        this.cn=cn;
        this.idSolicitud = idSolicitud ;
        solicitudTrasladoDao = new SolicitudTrasladoDaoImpl(cn);
        organoDao = new OrganoDaoImpl(cn);
        initComponents();
        AsignarCampos();
    }

       
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btncotizacion = new javax.swing.JButton();
        btnrechazar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        lbcodigo = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        txtSede = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtFecha = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtmonto = new javax.swing.JLabel();
        txturgencia = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        btncotizacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cotizar.jpg"))); // NOI18N
        btncotizacion.setText("Cotizar");
        btncotizacion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btncotizacionActionPerformed(evt);
            }
        });

        btnrechazar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/rechazar.jpg"))); // NOI18N
        btnrechazar.setText("Rechazar");
        btnrechazar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnrechazarActionPerformed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(204, 204, 255));

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel9.setText("Código:");

        lbcodigo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lbcodigo.setText("Codigo");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel2.setText("Origen: ");

        txtSede.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtSede.setText("Origen");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel3.setText("Fecha:");

        txtFecha.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtFecha.setText("Fecha");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel5.setText("Monto:");

        txtmonto.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txtmonto.setText("Monto");

        txturgencia.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        txturgencia.setText(" Urgencia");

        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel7.setText("Urgencia:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(103, 103, 103)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel9))
                        .addGap(38, 38, 38)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbcodigo)
                            .addComponent(txtSede)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7))
                        .addGap(28, 28, 28)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtFecha)
                            .addComponent(txturgencia)
                            .addComponent(txtmonto))))
                .addContainerGap(101, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(lbcodigo))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtSede))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtFecha))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtmonto))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txturgencia)
                    .addComponent(jLabel7))
                .addContainerGap(46, Short.MAX_VALUE))
        );

        jPanel2.setBackground(new java.awt.Color(204, 204, 255));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel1.setText("SOLICITUD DE FONDO");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(59, 59, 59)
                .addComponent(jLabel1)
                .addContainerGap(61, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/Back_2.png"))); // NOI18N
        jButton1.setText("Atrás");

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes/cancelar.png"))); // NOI18N
        jButton2.setText("Cancelar");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addGap(95, 95, 95)
                        .addComponent(btnrechazar, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(58, 58, 58)
                        .addComponent(btncotizacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(26, 26, 26)
                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33))
            .addGroup(layout.createSequentialGroup()
                .addGap(198, 198, 198)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(38, 38, 38)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(39, 39, 39)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btncotizacion)
                    .addComponent(btnrechazar)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(47, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    public void AsignarCampos(){                   
        Date Fecha;
        String cadf,cad1,cad2,cad3;
        solicitudtraslado=new SolicitudTraslado();
        solicitudtraslado = solicitudTrasladoDao.buscarSolicitud(idSolicitud);
        System.out.println(idSolicitud+" .... "+solicitudtraslado.getIDSolicitud());
        lbcodigo.setText(solicitudtraslado.getIDSolicitud());
        txtSede.setText(organoDao.buscarOrganoxID(solicitudtraslado.getIDOrgano()).getNombreOrgano());
        Fecha = solicitudtraslado.getFechaEmision();
        cadf = (Fecha.getDay()+"-"+Fecha.getMonth()+"-"+Fecha.getYear());
        //txtFecha.setText(cadf);
        txtFecha.setText(solicitudtraslado.getFechaEmision().toString());
        txtmonto.setText(String.valueOf(solicitudtraslado.getMontoSolcitado()));
        txturgencia.setText(solicitudtraslado.getUrgencia());
        idOrgano = solicitudTrasladoDao.buscarSolicitud(idSolicitud).getIDOrgano();
    }

    private void btncotizacionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btncotizacionActionPerformed
        
  /*      SolicitudTraslado solicitudtraslado = new SolicitudTraslado();
        solicitudtraslado.setEstadoSolicitud("P");
        Generar_Cotizacion gnc = new Generar_Cotizacion();
        GestionarCotizacion2.setVisible(true);
    */    
        solicitudTrasladoDao.aprobarSolicitud(idSolicitud);
        JOptionPane.showMessageDialog(null, "La solicitud ha sido marcada como pendiente");
        System.out.println("GC2 .. GC  : "+idOrgano+"  "+idSolicitud);
        Generar_Cotizacion gc = new Generar_Cotizacion(idOrgano, idSolicitud, cn);
        gc.setVisible(true);
    }//GEN-LAST:event_btncotizacionActionPerformed

    private void btnrechazarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnrechazarActionPerformed
        
  /*      SolicitudTraslado solicitudtraslado = new SolicitudTraslado();
        solicitudtraslado.setEstadoSolicitud("R");
      
    */   
        solicitudTrasladoDao.rechazarSolicitud(idSolicitud);
        JOptionPane.showMessageDialog(null, "La solicitud ha sido rechazada");
               
        
    }//GEN-LAST:event_btnrechazarActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btncotizacion;
    private javax.swing.JButton btnrechazar;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lbcodigo;
    private javax.swing.JLabel txtFecha;
    private javax.swing.JLabel txtSede;
    private javax.swing.JLabel txtmonto;
    private javax.swing.JLabel txturgencia;
    // End of variables declaration//GEN-END:variables
}
